Add contact and invoice party

issue8992
review274701003
This commit is contained in:
Cédric Krier committed 2020-03-28 14:25:57 +01:00
1 parent 26d61f626c
commit 7b4715a6db
5 files changed
+56 -16

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
* Add contact and invoice party on sale
* Add salable products menu entry
Version 5.4.0 - 2019-11-04
+2
View File
@@ -13,6 +13,8 @@ quantity. Here is the extensive list of the fields, most of them are
optional or completed with sensible default values:
- Party: The customer.
- Contact: The contact who placed the order.
- Invoice Party: An optional different party to invoice.
- Invoice Address: The invoice address of the customer.
- Shipment Party: An optional different party where the shipment will be sent.
- Shipment Address: The address where the shipment will be sent.
+1
View File
@@ -13,6 +13,7 @@ class Replace(metaclass=PoolMeta):
def fields_to_replace(cls):
return super().fields_to_replace() + [
('sale.sale', 'party'),
('sale.sale', 'invoice_party'),
('sale.sale', 'shipment_party'),
]
+41 -14
View File
@@ -101,11 +101,27 @@ class Sale(Workflow, ModelSQL, ModelView, TaxableMixin):
depends=['state'])
party_lang = fields.Function(fields.Char('Party Language'),
'on_change_with_party_lang')
contact = fields.Many2One(
'party.contact_mechanism', "Contact",
search_context={
'related_party': Eval('party'),
},
depends=['party'])
invoice_party = fields.Many2One('party.party', "Invoice Party",
states={
'readonly': ((Eval('state') != 'draft')
| Eval('lines', [0])),
},
depends=['state'])
invoice_address = fields.Many2One('party.address', 'Invoice Address',
domain=[('party', '=', Eval('party'))], states={
domain=[
('party', '=', If(Bool(Eval('invoice_party')),
Eval('invoice_party'), Eval('party'))),
],
states={
'readonly': Eval('state') != 'draft',
'required': ~Eval('state').in_(['draft', 'quotation', 'cancel']),
}, depends=['state', 'party'])
}, depends=['party', 'invoice_party', 'state'])
shipment_party = fields.Many2One('party.party', 'Shipment Party',
states={
'readonly': (Eval('state') != 'draft'),
@@ -354,19 +370,29 @@ class Sale(Workflow, ModelSQL, ModelView, TaxableMixin):
def default_shipment_state():
return 'none'
@fields.depends('party', 'shipment_party', 'payment_term')
@fields.depends('party', 'invoice_party', 'shipment_party', 'payment_term')
def on_change_party(self):
self.invoice_address = None
if not self.invoice_party:
self.invoice_address = None
if not self.shipment_party:
self.shipment_address = None
self.payment_term = self.default_payment_term()
if self.party:
self.invoice_address = self.party.address_get(type='invoice')
if not self.invoice_party:
self.invoice_address = self.party.address_get(type='invoice')
if not self.shipment_party:
self.shipment_address = self.party.address_get(type='delivery')
if self.party.customer_payment_term:
self.payment_term = self.party.customer_payment_term
@fields.depends('party', 'invoice_party')
def on_change_invoice_party(self):
if self.invoice_party:
self.invoice_address = self.invoice_party.address_get(
type='invoice')
elif self.party:
self.invoice_address = self.party.address_get(type='invoice')
@fields.depends('party', 'shipment_party')
def on_change_shipment_party(self):
if self.shipment_party:
@@ -715,13 +741,14 @@ class Sale(Workflow, ModelSQL, ModelView, TaxableMixin):
'Return invoice'
pool = Pool()
Invoice = pool.get('account.invoice')
party = self.invoice_party or self.party
invoice = Invoice(
company=self.company,
type='out',
party=self.party,
party=party,
invoice_address=self.invoice_address,
currency=self.currency,
account=self.party.account_receivable_used,
account=party.account_receivable_used,
)
invoice.on_change_type()
invoice.payment_term = self.payment_term
@@ -773,10 +800,9 @@ class Sale(Workflow, ModelSQL, ModelView, TaxableMixin):
def _get_shipment_sale(self, Shipment, key):
values = {
'customer': (self.shipment_party.id if self.shipment_party
else self.party.id),
'delivery_address': self.shipment_address.id,
'company': self.company.id,
'customer': self.shipment_party or self.party,
'delivery_address': self.shipment_address,
'company': self.company,
}
values.update(dict(key))
return Shipment(**values)
@@ -1150,7 +1176,8 @@ class SaleLine(sequence_ordered(), ModelSQL, ModelView):
context['taxes'] = [t.id for t in self.taxes or []]
return context
@fields.depends('product', 'unit', 'sale', '_parent_sale.party',
@fields.depends('product', 'unit', 'sale',
'_parent_sale.party', '_parent_sale.invoice_party',
methods=['compute_taxes', 'compute_unit_price',
'on_change_with_amount'])
def on_change_product(self):
@@ -1158,8 +1185,8 @@ class SaleLine(sequence_ordered(), ModelSQL, ModelView):
return
party = None
if self.sale and self.sale.party:
party = self.sale.party
if self.sale:
party = self.sale.invoice_party or self.sale.party
# Set taxes before unit_price to have taxes in context of sale price
self.taxes = self.compute_taxes(party)
+11 -2
View File
@@ -4,19 +4,28 @@ this repository contains the full copyright notices and license terms. -->
<form col="6">
<label name="party"/>
<field name="party"/>
<label name="invoice_address"/>
<field name="invoice_address"/>
<label name="contact"/>
<field name="contact"/>
<label name="number"/>
<field name="number"/>
<label name="invoice_party"/>
<field name="invoice_party"/>
<label name="invoice_address"/>
<field name="invoice_address"/>
<newline/>
<label name="shipment_party"/>
<field name="shipment_party"/>
<label name="shipment_address"/>
<field name="shipment_address"/>
<newline/>
<label name="description"/>
<field name="description" colspan="3"/>
<label name="reference"/>
<field name="reference"/>
<notebook colspan="6">
<page string="Sale" id="sale">
<label name="sale_date"/>