mirror of
https://github.com/NaN-tic/trytond-intercompany_create_sales_from_purchase.git
synced 2023-12-14 06:23:01 +01:00
FIX in case company has not company user
task-035279
This commit is contained in:
parent
2cc24414af
commit
cafe68446e
|
@ -1,11 +1,10 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part company_logo module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="company_view_form">
|
||||
<field name="model">company.company</field>
|
||||
<field name="type" eval="None"/>
|
||||
<field name="inherit" ref="company.company_view_form"/>
|
||||
<field name="name">company_form</field>
|
||||
</record>
|
||||
|
|
13
locale/ca.po
13
locale/ca.po
|
@ -4,8 +4,17 @@ msgstr "Content-Type: text/plain; charset=utf-8\n"
|
|||
|
||||
msgctxt "error:purchase.purchase:"
|
||||
msgid ""
|
||||
"The purchase %s has to be assigned to a delivery address or a warehouse with"
|
||||
"The purchase \"%s\" has to be assigned to a delivery address or a warehouse with"
|
||||
" an address assigned."
|
||||
msgstr ""
|
||||
"La compra %s ha d'assignar-se a una adreça de lliurament o a un magatzem amb "
|
||||
"La compra \"%s\" ha d'assignar-se a una adreça de lliurament o a un magatzem amb "
|
||||
"una adreça assignada."
|
||||
|
||||
msgctxt "field:company.company,intercompany_user:"
|
||||
msgid "Company User"
|
||||
msgstr "Usuari empresa"
|
||||
|
||||
msgctxt "help:company.company,intercompany_user:"
|
||||
msgid "User with company rules when create a intercompany sale from purchases."
|
||||
msgstr ""
|
||||
"Usuari amb regles de l'empresa per crear la venta entre empreses desde compras."
|
||||
|
|
13
locale/es.po
13
locale/es.po
|
@ -4,8 +4,17 @@ msgstr "Content-Type: text/plain; charset=utf-8\n"
|
|||
|
||||
msgctxt "error:purchase.purchase:"
|
||||
msgid ""
|
||||
"The purchase %s has to be assigned to a delivery address or a warehouse with"
|
||||
"The purchase \"%s\" has to be assigned to a delivery address or a warehouse with"
|
||||
" an address assigned."
|
||||
msgstr ""
|
||||
"La compra %s debe asignarse a una dirección de entrega o a un almacén con "
|
||||
"La compra \"%s\" debe asignarse a una dirección de entrega o a un almacén con "
|
||||
"una dirección asignada."
|
||||
|
||||
msgctxt "field:company.company,intercompany_user:"
|
||||
msgid "Company User"
|
||||
msgstr "Usuario empresa"
|
||||
|
||||
msgctxt "help:company.company,intercompany_user:"
|
||||
msgid "User with company rules when create a intercompany sale from purchases."
|
||||
msgstr ""
|
||||
"Usuario con reglas de la empresa para crear la venta entre empresas desde compras."
|
||||
|
|
31
purchase.py
31
purchase.py
|
@ -4,13 +4,14 @@ from trytond.pool import Pool, PoolMeta
|
|||
from trytond.model import ModelView, fields
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
__all__ = ['Purchase', 'Company']
|
||||
__all__ = ['Company', 'Purchase']
|
||||
|
||||
|
||||
class Company(metaclass=PoolMeta):
|
||||
__name__ = 'company.company'
|
||||
|
||||
company_user = fields.Many2One('res.user', 'Company User')
|
||||
intercompany_user = fields.Many2One('res.user', 'Company User',
|
||||
help='User with company rules when create a intercompany sale '
|
||||
'from purchases.')
|
||||
|
||||
|
||||
class Purchase(metaclass=PoolMeta):
|
||||
|
@ -20,7 +21,7 @@ class Purchase(metaclass=PoolMeta):
|
|||
def __setup__(cls):
|
||||
super(Purchase, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'empty_address': ('The purchase %s has to be assigned to '
|
||||
'empty_address': ('The purchase "%s" has to be assigned to '
|
||||
'a delivery address or a warehouse with an '
|
||||
'address assigned.')
|
||||
})
|
||||
|
@ -28,17 +29,21 @@ class Purchase(metaclass=PoolMeta):
|
|||
@classmethod
|
||||
@ModelView.button
|
||||
def process(cls, purchases):
|
||||
super(Purchase, cls).process(purchases)
|
||||
pool = Pool()
|
||||
Company = pool.get('company.company')
|
||||
Sale = pool.get('sale.sale')
|
||||
self_companies = {x.party.id for x in Company.search([])}
|
||||
to_create = []
|
||||
|
||||
super(Purchase, cls).process(purchases)
|
||||
|
||||
self_companies = {x.party.id for x in Company.search([])}
|
||||
|
||||
to_create = []
|
||||
for purchase in purchases:
|
||||
if purchase.party.id not in self_companies:
|
||||
continue
|
||||
to_create.append(purchase.create_intercompany_sale())
|
||||
new_sale = purchase.create_intercompany_sale()
|
||||
if new_sale:
|
||||
to_create.append(new_sale)
|
||||
if to_create:
|
||||
Sale.save(to_create)
|
||||
|
||||
|
@ -46,15 +51,18 @@ class Purchase(metaclass=PoolMeta):
|
|||
pool = Pool()
|
||||
Sale = pool.get('sale.sale')
|
||||
Company = pool.get('company.company')
|
||||
company, = Company.search([('party', '=', self.party.id)])
|
||||
|
||||
company, = Company.search([('party', '=', self.party.id)], limit=1)
|
||||
if not company.intercompany_user:
|
||||
return
|
||||
|
||||
purchase_lines = [(l.product.id, l.unit_price, l.unit,
|
||||
l.quantity) for l in self.lines if l.type == 'line']
|
||||
|
||||
with Transaction().set_user(company.company_user.id), \
|
||||
with Transaction().set_user(company.intercompany_user.id), \
|
||||
Transaction().set_context(
|
||||
company=company.id,
|
||||
companies=Company.search([]),
|
||||
companies=[company.id],
|
||||
_check_access=False):
|
||||
sale = Sale()
|
||||
sale.comment = self.comment
|
||||
|
@ -88,6 +96,7 @@ class Purchase(metaclass=PoolMeta):
|
|||
Product = pool.get('product.product')
|
||||
|
||||
product_id, list_price, unit, quantity = line
|
||||
|
||||
sale_line = SaleLine()
|
||||
sale_line.product = Product(product_id)
|
||||
sale_line.unit = unit
|
||||
|
|
|
@ -63,7 +63,7 @@ Create customer user::
|
|||
>>> supplier_user.main_company = company_supplier
|
||||
>>> supplier_user.company = company_supplier
|
||||
>>> supplier_user.save()
|
||||
>>> company_supplier.company_user = supplier_user
|
||||
>>> company_supplier.intercompany_user = supplier_user
|
||||
>>> company_supplier.save()
|
||||
|
||||
Create chart of accounts::
|
||||
|
@ -94,7 +94,6 @@ Create tax::
|
|||
>>> tax_customer = create_tax(Decimal('.10'), company_customer)
|
||||
>>> tax_customer.save()
|
||||
|
||||
|
||||
Create account categories::
|
||||
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
|
@ -144,7 +143,6 @@ Create payment term::
|
|||
>>> payment_term = create_payment_term()
|
||||
>>> payment_term.save()
|
||||
|
||||
|
||||
Purchase 5 products::
|
||||
|
||||
>>> Purchase = Model.get('purchase.purchase')
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part jasper_reports_options module for Tryton.
|
||||
The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath
|
||||
expr="/form/notebook"
|
||||
position="before">
|
||||
<label name="company_user"/>
|
||||
<field name="company_user"/>
|
||||
<xpath expr="/form/notebook" position="before">
|
||||
<label name="intercompany_user"/>
|
||||
<field name="intercompany_user"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
|
Loading…
Reference in a new issue