Ed Leafe wrote:
> On Oct 10, 2008, at 6:45 PM, Paul McNett wrote:
> 
>> File "/home/pmcnett/py/sbs/shutter_studio/trunk/clients/ 
>> shutter_studio/ui/FrmProductionOrders.py", line 41, in new
>>   self.newProductionOrder()
>> File "/home/pmcnett/py/sbs/shutter_studio/trunk/clients/ 
>> shutter_studio/ui/FrmProductionOrders.py", line 60, in  
>> newProductionOrder
>>   self.getBizobj("production_orders").new(dlg.Fields)
>> File "/home/pmcnett/py/sbs/shutter_studio/trunk/clients/ 
>> shutter_studio/biz/orders.py", line 141, in new
>>   self.save()
> 
> 
>       This is the part that confuses me: it looks like you're calling  
> new(), and then saving a different object immediately, before the new  
> process has finished for the first bizobj. Is the record being saved  
> in orders.py a new or existing record?

I've overridden the new() method in my bizobj. Here's the code:

103   def new(self, fields=None):
104     if fields is None:
105       fields = {}
106     self.super()
107     for k, v in fields.items():
108       self.setFieldVal(k, v)
109     needed = []
110     for neededField in (("cust_id", "Customer"),
111                         ("material_type_id", "Material type"),
112                         ("sidemark", "Sidemark")):
113       if not self.getFieldVal(neededField[0]):
114         needed.append("%s needed." % neededField[1])
115 
116     if not self.getFieldVal("prod_cust_id"):
117       if self.Application.showProductLines():
118         # refuse it.
119         needed.append("Product Line needed.")
120       else:
121         # Set it to the default.
122         cust_id = self.Record.cust_id
123         if cust_id:
124           default = self.getDefaultProdCust(cust_id)
125           if default:
126             self.Record.prod_cust_id = default
127           else:
128             # Should never happen, as all customers should have a default 
product line.
129             needed.append("Product Line needed.")
130         else:
131           # Won't work anyway because there's no customer chosen.
132           pass
133     if needed:
134       self.cancel()
135       raise dException.BusinessRuleViolation, "\n".join(needed)
136 
137     self.Record.status_id = 10
138     self.Record.order_date = datetime.date.today()
139     self.fillCustomerAddressFields()
140     self.fillDerivedFields()
141     self.save()

The purpose is to make sure that certain required fields are filled in 
immediately. If the required fields aren't filled in, then we cancel the new 
record immediately. Else, we save().

Paul


_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: http://leafe.com/archives/byMID/[EMAIL PROTECTED]

Reply via email to