[FIX] account_budget : Overlapping budget lines

lp bug: https://launchpad.net/bugs/880751 fixed

bzr revid: mdi@tinyerp.com-20111101112840-hk73d95aqppjqc9g
This commit is contained in:
Divyesh Makwana (Open ERP) 2011-11-01 16:58:40 +05:30
parent 3d22bb8b55
commit 2af51acb67
2 changed files with 49 additions and 33 deletions

View File

@ -111,7 +111,7 @@ class crossovered_budget_lines(osv.osv):
def _prac_amt(self, cr, uid, ids, context=None):
res = {}
result = 0.0
if context is None:
if context is None:
context = {}
for line in self.browse(cr, uid, ids, context=context):
acc_ids = [x.id for x in line.general_budget_id.account_ids]
@ -141,7 +141,7 @@ class crossovered_budget_lines(osv.osv):
def _theo_amt(self, cr, uid, ids, context=None):
res = {}
if context is None:
if context is None:
context = {}
for line in self.browse(cr, uid, ids, context=context):
today = datetime.datetime.today()
@ -202,6 +202,22 @@ class crossovered_budget_lines(osv.osv):
'company_id': fields.related('crossovered_budget_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True)
}
def _check_budget_lines(self, cr, uid, ids, context=None):
current_budget_line = self.browse(cr, uid, ids, context=context)[0]
obj_budget_ids = self.search(cr, uid, [('general_budget_id', '=', current_budget_line.general_budget_id.id)], context=context)
obj_budget_ids.remove(ids[0])
data_budget_yr = self.browse(cr, uid, obj_budget_ids, context=context)
for old_line in data_budget_yr:
if old_line.general_budget_id.id == current_budget_line['general_budget_id'].id:
if old_line.date_from <= current_budget_line['date_from'] <= old_line.date_to or \
old_line.date_from <= current_budget_line['date_to'] <= old_line.date_to:
return False
return True
_constraints = [
(_check_budget_lines, 'Error! You can not define overlapping budget lines for the same budgetary position.',['date_from', 'date_to'])
]
crossovered_budget_lines()
class account_analytic_account(osv.osv):

View File

@ -47,15 +47,15 @@
<field eval="str(time.localtime(time.time())[0]+1)+'-01-01'" name="date_from"/>
<field eval="-500.0" name="planned_amount"/>
<field name="crossovered_budget_id" ref="crossovered_budget_budgetpessimistic0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-31'" name="date_to"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-01-31'" name="date_to"/>
</record>
<record id="crossovered_budget_lines_1" model="crossovered.budget.lines">
<field name="analytic_account_id" ref="account.analytic_consultancy"/>
<field name="general_budget_id" ref="account_budget_post_purchase0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-01-01'" name="date_from"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-02-01'" name="date_from"/>
<field eval="-250.0" name="planned_amount"/>
<field name="crossovered_budget_id" ref="crossovered_budget_budgetoptimistic0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-31'" name="date_to"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-02-28'" name="date_to"/>
</record>
<record id="crossovered_budget_lines_2" model="crossovered.budget.lines">
<field name="analytic_account_id" ref="account.analytic_consultancy"/>
@ -63,124 +63,124 @@
<field eval="str(time.localtime(time.time())[0]+1)+'-01-01'" name="date_from"/>
<field eval="500.0" name="planned_amount"/>
<field name="crossovered_budget_id" ref="crossovered_budget_budgetpessimistic0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-31'" name="date_to"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-01-31'" name="date_to"/>
</record>
<record id="crossovered_budget_lines_3" model="crossovered.budget.lines">
<field name="analytic_account_id" ref="account.analytic_consultancy"/>
<field name="general_budget_id" ref="account_budget_post_sales0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-01-07'" name="date_from"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-02-07'" name="date_from"/>
<field eval="900.0" name="planned_amount"/>
<field name="crossovered_budget_id" ref="crossovered_budget_budgetoptimistic0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-31'" name="date_to"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-02-28'" name="date_to"/>
</record>
<record id="crossovered_budget_lines_4" model="crossovered.budget.lines">
<field name="analytic_account_id" ref="account.analytic_consultancy"/>
<field name="general_budget_id" ref="account_budget_post_sales0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-01-01'" name="date_from"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-03-01'" name="date_from"/>
<field eval="300.0" name="planned_amount"/>
<field name="crossovered_budget_id" ref="crossovered_budget_budgetoptimistic0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-06'" name="date_to"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-03-15'" name="date_to"/>
</record>
</data>
<data noupdate="1">
<record id="crossovered_budget_lines_5" model="crossovered.budget.lines">
<field name="analytic_account_id" ref="account.analytic_super_product_trainings"/>
<field name="general_budget_id" ref="account_budget_post_sales0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-09-01'" name="date_from"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-03-16'" name="date_from"/>
<field eval="375.0" name="planned_amount"/>
<field name="crossovered_budget_id" ref="crossovered_budget_budgetpessimistic0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-03'" name="paid_date"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-31'" name="date_to"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-03-31'" name="date_to"/>
</record>
<record id="crossovered_budget_lines_6" model="crossovered.budget.lines">
<field name="analytic_account_id" ref="account.analytic_super_product_trainings"/>
<field name="general_budget_id" ref="account_budget_post_purchase0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-09-01'" name="date_from"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-04-01'" name="date_from"/>
<field eval="-150.0" name="planned_amount"/>
<field name="crossovered_budget_id" ref="crossovered_budget_budgetpessimistic0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-31'" name="date_to"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-04-30'" name="date_to"/>
</record>
<record id="crossovered_budget_lines_7" model="crossovered.budget.lines">
<field name="analytic_account_id" ref="account.analytic_super_product_trainings"/>
<field name="general_budget_id" ref="account_budget_post_sales0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-09-01'" name="date_from"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-05-01'" name="date_from"/>
<field eval="375.0" name="planned_amount"/>
<field name="crossovered_budget_id" ref="crossovered_budget_budgetoptimistic0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-03'" name="paid_date"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-31'" name="date_to"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-05-31'" name="date_to"/>
</record>
</data>
<data noupdate="1">
<record id="crossovered_budget_lines_8" model="crossovered.budget.lines">
<field name="analytic_account_id" ref="account.analytic_seagate_p1"/>
<field name="general_budget_id" ref="account_budget_post_purchase0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-01-01'" name="date_from"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-06-01'" name="date_from"/>
<field eval="-7500.0" name="planned_amount"/>
<field name="crossovered_budget_id" ref="crossovered_budget_budgetpessimistic0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-31'" name="date_to"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-06-15'" name="date_to"/>
</record>
<record id="crossovered_budget_lines_9" model="crossovered.budget.lines">
<field name="analytic_account_id" ref="account.analytic_seagate_p1"/>
<field name="general_budget_id" ref="account_budget_post_purchase0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-01-01'" name="date_from"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-06-16'" name="date_from"/>
<field eval="-5000.0" name="planned_amount"/>
<field name="crossovered_budget_id" ref="crossovered_budget_budgetpessimistic0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-31'" name="date_to"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-06-30'" name="date_to"/>
</record>
<record id="crossovered_budget_lines_10" model="crossovered.budget.lines">
<field name="analytic_account_id" ref="account.analytic_seagate_p1"/>
<field name="general_budget_id" ref="account_budget_post_purchase0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-01-01'" name="date_from"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-07-01'" name="date_from"/>
<field eval="-2000.0" name="planned_amount"/>
<field name="crossovered_budget_id" ref="crossovered_budget_budgetoptimistic0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-31'" name="date_to"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-07-15'" name="date_to"/>
</record>
<record id="crossovered_budget_lines_11" model="crossovered.budget.lines">
<field name="analytic_account_id" ref="account.analytic_seagate_p1"/>
<field name="general_budget_id" ref="account_budget_post_sales0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-01-01'" name="date_from"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-07-16'" name="date_from"/>
<field eval="20000.0" name="planned_amount"/>
<field name="crossovered_budget_id" ref="crossovered_budget_budgetpessimistic0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-31'" name="date_to"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-07-31'" name="date_to"/>
</record>
<record id="crossovered_budget_lines_12" model="crossovered.budget.lines">
<field name="analytic_account_id" ref="account.analytic_seagate_p1"/>
<field name="general_budget_id" ref="account_budget_post_sales0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-01-01'" name="date_from"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-08-01'" name="date_from"/>
<field eval="20000.0" name="planned_amount"/>
<field name="crossovered_budget_id" ref="crossovered_budget_budgetoptimistic0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-31'" name="date_to"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-08-15'" name="date_to"/>
</record>
</data>
<data noupdate="1">
<record id="crossovered_budget_lines_13" model="crossovered.budget.lines">
<field name="analytic_account_id" ref="account.analytic_seagate_p2"/>
<field name="general_budget_id" ref="account_budget_post_purchase0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-01-01'" name="date_from"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-08-16'" name="date_from"/>
<field eval="-3000.0" name="planned_amount"/>
<field name="crossovered_budget_id" ref="crossovered_budget_budgetpessimistic0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-31'" name="date_to"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-08-31'" name="date_to"/>
</record>
<record id="crossovered_budget_lines_14" model="crossovered.budget.lines">
<field name="analytic_account_id" ref="account.analytic_seagate_p2"/>
<field name="general_budget_id" ref="account_budget_post_purchase0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-01-01'" name="date_from"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-09-01'" name="date_from"/>
<field eval="-1000.0" name="planned_amount"/>
<field name="crossovered_budget_id" ref="crossovered_budget_budgetoptimistic0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-31'" name="date_to"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-09-15'" name="date_to"/>
</record>
<record id="crossovered_budget_lines_15" model="crossovered.budget.lines">
<field name="analytic_account_id" ref="account.analytic_seagate_p2"/>
<field name="general_budget_id" ref="account_budget_post_sales0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-01-01'" name="date_from"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-09-16'" name="date_from"/>
<field eval="10000.0" name="planned_amount"/>
<field name="crossovered_budget_id" ref="crossovered_budget_budgetpessimistic0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-31'" name="date_to"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-09-30'" name="date_to"/>
</record>
<record id="crossovered_budget_lines_16" model="crossovered.budget.lines">
<field name="analytic_account_id" ref="account.analytic_seagate_p2"/>
<field name="general_budget_id" ref="account_budget_post_sales0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-01-01'" name="date_from"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-10-01'" name="date_from"/>
<field eval="10000.0" name="planned_amount"/>
<field name="crossovered_budget_id" ref="crossovered_budget_budgetoptimistic0"/>
<field eval="str(time.localtime(time.time())[0]+1)+'-12-31'" name="date_to"/>