Don't set default unit price on invoice line
issue4857 review23281003
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
* Don't set default unit price on invoice line
|
||||
* Allow to modify some fields of posted invoice line
|
||||
|
||||
Version 3.6.0 - 2015-04-20
|
||||
|
||||
+2
-37
@@ -1691,16 +1691,11 @@ class InvoiceLine(ModelSQL, ModelView, TaxableMixin):
|
||||
'''
|
||||
return {}
|
||||
|
||||
@fields.depends('product', 'unit', 'quantity', 'description',
|
||||
'_parent_invoice.type', '_parent_invoice.party',
|
||||
'_parent_invoice.currency', '_parent_invoice.currency_date',
|
||||
'party', 'currency', 'invoice', 'invoice_type')
|
||||
@fields.depends('product', 'unit', 'description', '_parent_invoice.type',
|
||||
'_parent_invoice.party', 'party', 'invoice', 'invoice_type')
|
||||
def on_change_product(self):
|
||||
pool = Pool()
|
||||
Product = pool.get('product.product')
|
||||
Company = pool.get('company.company')
|
||||
Currency = pool.get('currency.currency')
|
||||
Date = pool.get('ir.date')
|
||||
|
||||
if not self.product:
|
||||
return
|
||||
@@ -1714,31 +1709,11 @@ class InvoiceLine(ModelSQL, ModelView, TaxableMixin):
|
||||
if party and party.lang:
|
||||
context['language'] = party.lang.code
|
||||
|
||||
company = None
|
||||
if Transaction().context.get('company'):
|
||||
company = Company(Transaction().context['company'])
|
||||
currency = None
|
||||
currency_date = Date.today()
|
||||
if self.invoice and self.invoice.currency_date:
|
||||
currency_date = self.invoice.currency_date
|
||||
# TODO check if today date is correct
|
||||
if self.invoice and self.invoice.currency:
|
||||
currency = self.invoice.currency
|
||||
elif self.currency:
|
||||
currency = self.currency
|
||||
|
||||
if self.invoice and self.invoice.type:
|
||||
type_ = self.invoice.type
|
||||
else:
|
||||
type_ = self.invoice_type
|
||||
if type_ in ('in_invoice', 'in_credit_note'):
|
||||
if company and currency:
|
||||
with Transaction().set_context(date=currency_date):
|
||||
self.unit_price = Currency.compute(
|
||||
company.currency, self.product.cost_price,
|
||||
currency, round=False)
|
||||
else:
|
||||
self.unit_price = self.product.cost_price
|
||||
try:
|
||||
self.account = self.product.account_expense_used
|
||||
except Exception:
|
||||
@@ -1758,13 +1733,6 @@ class InvoiceLine(ModelSQL, ModelView, TaxableMixin):
|
||||
taxes.extend(tax_ids)
|
||||
self.taxes = taxes
|
||||
else:
|
||||
if company and currency:
|
||||
with Transaction().set_context(date=currency_date):
|
||||
self.unit_price = Currency.compute(
|
||||
company.currency, self.product.list_price,
|
||||
currency, round=False)
|
||||
else:
|
||||
self.unit_price = self.product.list_price
|
||||
try:
|
||||
self.account = self.product.account_revenue_used
|
||||
except Exception:
|
||||
@@ -1793,9 +1761,6 @@ class InvoiceLine(ModelSQL, ModelView, TaxableMixin):
|
||||
self.unit = self.product.default_uom.id
|
||||
self.unit_digits = self.product.default_uom.digits
|
||||
|
||||
self.type = 'line'
|
||||
self.amount = self.on_change_with_amount()
|
||||
|
||||
@fields.depends('product')
|
||||
def on_change_with_product_uom_category(self, name=None):
|
||||
if self.product:
|
||||
|
||||
@@ -106,6 +106,7 @@ Create invoice::
|
||||
>>> invoice.lines.append(line)
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 5
|
||||
>>> line.unit_price = Decimal('40')
|
||||
>>> line = InvoiceLine()
|
||||
>>> invoice.lines.append(line)
|
||||
>>> line.account = revenue
|
||||
|
||||
@@ -107,6 +107,7 @@ Create invoice with alternate currency::
|
||||
>>> line = invoice.lines.new()
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 5
|
||||
>>> line.unit_price = Decimal('80')
|
||||
>>> line.amount
|
||||
Decimal('400.00')
|
||||
>>> line = invoice.lines.new()
|
||||
@@ -146,6 +147,7 @@ Create invoice with alternate currency and negative taxes::
|
||||
>>> line = invoice.lines.new()
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 5
|
||||
>>> line.unit_price = Decimal('80')
|
||||
>>> _ = line.taxes.pop(0)
|
||||
>>> line.taxes.append(negative_tax)
|
||||
>>> line.amount
|
||||
|
||||
@@ -104,6 +104,7 @@ Create invoice::
|
||||
>>> invoice.lines.append(line)
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 5
|
||||
>>> line.unit_price = Decimal('20')
|
||||
>>> line = InvoiceLine()
|
||||
>>> invoice.lines.append(line)
|
||||
>>> line.account = expense
|
||||
@@ -178,6 +179,7 @@ Create a posted and a draft invoice to cancel::
|
||||
>>> line = invoice.lines.new()
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 1
|
||||
>>> line.unit_price = Decimal('20')
|
||||
>>> invoice.click('post')
|
||||
>>> invoice_draft, = Invoice.duplicate([invoice])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user